package com.oig.sys.workflow.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
@EnableScheduling
public class SpringTaskConfig {

    @Bean
    public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setThreadNamePrefix("us-task-");
        threadPoolTaskScheduler.setPoolSize(5);
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true); //关闭线程池等待线程执行完毕
        threadPoolTaskScheduler.setAwaitTerminationSeconds(1000);
        threadPoolTaskScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return threadPoolTaskScheduler ;
    }



}
